package com.example.springbootweb.bean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author: wukangrong
 * @date: 2019/8/19 16:58
 * @description: MyMethodInterceptor
 */
@Slf4j
public class MyMethodInterceptor implements MethodInterceptor {
    /**
     * sub：cglib生成的代理对象
     * method：被代理对象方法
     * objects：方法入参
     * methodProxy: 代理方法
     */
    @Override
    public Object intercept(Object sub, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        log.info("======插入前置通知======");
        Object object = methodProxy.invokeSuper(sub, objects);
        log.info("======插入后者通知======");
        return object;
    }
}
